﻿using System.Windows;
using Microsoft.Practices.Unity;
using Microsoft.Practices.Composite.UnityExtensions;
using Microsoft.Practices.Composite.Modularity;

namespace Core
{
    /// <summary>
    /// Loads modules and, registers services in unity container, prepares master page
    /// </summary>
    public class Bootstrapper : UnityBootstrapper
    {
        public IConfig Config { get; set; }

        public Bootstrapper(IConfig config)
        {
            this.Config = config;
        }
        
        public void KickOff()
        {
           base.Run();
        }

        //protected override IUnityContainer CreateContainer()
        //{
        //    return Config.CreateUnityContainer();
        //}
        
        protected override DependencyObject CreateShell()
        {
            return Config.CreateAndSetRootVisual(Container);
        }

        protected override void InitializeModules()
        {
            Config.RegisterThemeLoaders(Container);
            Config.RegisterServices(Container); 
            Config.RegisterScreenManeger(Container);
            
            base.InitializeModules();
            Config.Initialize(Container);        
            Config.SetupShellViewModel(Container);
        }

        protected override IModuleCatalog GetModuleCatalog()
        {
            return Config.CreateModuleCatalog("/Core;component/ModuleCatalog.xaml");
        }
    }
}
